package com.candy.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBHelper {
    public static void main(String[] args) {
//（1）注册或实例化jdbc的驱动类
        String url="jdbc:mysql://localhost:3306/schoolinfo? characterEncoding=utf8 & useSSL=false & serverTimezone=UTC & rewriteBatchedStatements=true";
        String userName="root";
        String userPsw="123456";

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
//（2）获取数据库连接对象Connection
         Connection conn= DriverManager.getConnection(url,userName,userPsw);
//（3）获取数据库操作对象Statement（执行增删改查）
          Statement statement= conn.createStatement();
//（4）执行SQL语句，获取数据操作结果或者结果集对象ResultSet
            String selectSql="select * from studentinfo";
          ResultSet re= statement.executeQuery(selectSql);
          while (re.next()){
              System.out.print(re.getObject(1));
              System.out.print(re.getObject(2));
              System.out.print(re.getObject(3));
              System.out.print(re.getObject(4));
              System.out.print(re.getObject(5));
              System.out.println();
          }

        } catch (Exception e) {
            e.printStackTrace();
        }




//（5）解析结果集对象ResultSet，进行相关的业务处理；
    }
}
